<?python
from onlineapidoc.model import (page_type_codes, PAGE_TYPE_NORMAL_PAGE, PAGE_TYPE_DIR, PAGE_TYPE_LINK, lang_codes)
from turbogears.i18n.format import format_date
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="'../master.kid'">

<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title>Online API Doc - Space details for ${space.name}</title>
    <link href="/static/css/space.css" media="screen" rel="Stylesheet" type="text/css" />

<script language="Javascript">
function show_element(element_id) {
	var element = document.getElementById(element_id);
    element.style.display = "block";
}

function hide_element(element_id) {
	var element = document.getElementById(element_id);
    element.style.display = "none";
}

function change_by_type(page_type)
{
	if (page_type==$PAGE_TYPE_LINK)
	{
		show_element('link_dest');
        hide_element('template_choice');
	}
	else if (page_type==$PAGE_TYPE_DIR)
	{
		hide_element('template_choice');
        hide_element('link_dest');
	}
    else if (page_type==$PAGE_TYPE_NORMAL_PAGE)
	{
		show_element('template_choice');
        hide_element('link_dest');
	}
}

function confirm_del() {
    var msg = "${_("Are you sure you want to delete this page and all of its child?")}";
    if (confirm(msg)==true)
    {
        return true;
    }else
    {
        return false;
    }
}
</script>

<script py:if="current_page" language="Javascript">
function change_by_lang(lang_id)
{
    window.location = "/page/page_view/" + lang_id;
}
</script>
<script py:if="not current_page" language="Javascript">
function change_by_lang(lang_id)
{
    window.location = "/space/" + lang_id;
}
</script>


</head>

<body>  
<h2 py:if="not current_page" py:content="space.name">Name</h2>
<h2 py:if="current_page" py:content="current_page.name">Name</h2>
<div py:if="not tg.identity.anonymous" class="op splink">
<b>Operations</b>
<a href="#" onclick="toggle('new_page'); return false;">Add page</a>
<a py:if="not current_page" href="/space/space_setting/$space.id">Attribute</a>
<a py:if="current_page" href="/page/page_setting/$current_page.id">Attribute</a>
<a py:if="not tg.identity.anonymous and tg.identity.user.id == space.admin.id or 'root' in tg.identity.groups" href="/space/space_chm/$space.id">CHM</a>
<b>Language</b>
<select name="langs" onchange="change_by_lang(this.options[this.selectedIndex].value);">
<option py:for="k,v in lang_family.items()"
value="$v"
selected="${(None, '')[k == lang_codes[space.language]]}">
${k}
</option>
</select>
</div>
<div class="path splink">
<b>Path</b>
<a href="/space/$space.id">ROOT/</a>
<span py:if="page_path" py:for="k in page_path.keys()">
<a href="/page/page_view/$k">${page_path[k]}/</a>
</span>
</div>
<div id="new_page" style="display: none;">
<form id="form_new_page" action="/page/new_page_add" method="post">
<table>
<tr>
<td width="120"><b>Title</b></td>
<td><input type="text" name="name" size="50" /></td>
</tr>
<tr id="template_choice">
<td><b>Template</b></td>
<td>
<select name="template_id">
<option py:for="template in templates"
value="$template.id"
selected="${(None, '')[template.id == favorite_template]}">
${template.name}
</option>
</select>
</td>
</tr>
<tr id="link_dest" style="display: none;">
<td><b>Link Destination(Page ID)</b></td>
<td><input type="text" name="link_dest_id" size="10" /></td>
</tr>
<tr>
<td><b>Type</b></td>
<td>
<select name="type" onchange="change_by_type(this.options[this.selectedIndex].value);">
<option py:for="type in page_type_codes.keys()"
value="$type"
selected="${(None, '')[type == PAGE_TYPE_NORMAL_PAGE]}">
${page_type_codes[type]}
</option>
</select>
</td>
</tr>
</table>
<input py:if="current_page" name="parent_id" type="hidden" value="$current_page.id"/>
<input py:if="not current_page" name="parent_id" type="hidden" value=""/>
<input name="space_id" type="hidden" value="$space.id" />
<a href="#" onclick="submit('form_new_page'); return false;">add</a>
<a href="#" onclick="toggle('new_page'); return false;">cancel</a>
</form>
</div>

<table py:def="display_pages(pages)" class="pageview" cellspacing="0">
<tr>
<th width="4%">ID</th>
<th width="6%">Type</th>
<th width="40%">Title</th>
<th width="5%">Size</th>
<th width="20%">Operations</th>
<th width="25%">Last Updated By </th>
</tr>
<tr py:for="page in pages" id="page_$page.id" class="cls$page.type">
<td py:content="page.id">ID</td>
<td>[<span py:content="page_type_codes.get(page.type)">Type</span>]</td>
<td>
<span><a href="/page/page_view/$page.id" py:content="page.name">Title</a></span>
&nbsp;
<span py:if="PAGE_TYPE_DIR==page.type and page.content=='None'">♤</span>
<a py:if="PAGE_TYPE_DIR==page.type and page.content!='None'" href="/page/page_view/$page.content" title="Default Page">♠</a>
</td>
<td><span py:content="len(page.content)/1024 + 1">Size</span> K</td>
<td>
<a py:if="PAGE_TYPE_NORMAL_PAGE==page.type and ('page-edit' in tg.identity.permissions or 'root' in tg.identity.groups)" href="/page/page_edit/$page.id">Edit</a>
<a py:if="'page-edit' in tg.identity.permissions or 'root' in tg.identity.groups" href="/page/page_setting/$page.id">Attribute</a>
<a py:if="not tg.identity.anonymous and tg.identity.user.id == space.admin.id or 'root' in tg.identity.groups" href="/page/page_delete/$page.id" onclick="javascript:return confirm_del()">Delete</a>
<a py:if="len(page.link_copies) != len(space.children_space)" href="/page/page_translate/$page.id">Translate</a>
<a py:if="page.history_pages" href="/page/page_view_history/$page.id">History</a>
<a py:if="page.history_pages" href="/page/page_view_diff/$page.id">Diff</a>
</td>
<td>
<a href="mailto:$page.last_edit_user.email_address" py:content="page.last_edit_user.display_name">Author</a>
@
<span py:content="format_date(page.last_edit_time, format='long', time_format=' %H:%M')">Last edit time</span>
</td>
</tr>
</table>

<div id="space_pages" py:if="current_page" py:replace="display_pages(current_page.sub_pages)"/>
<div id="space_pages" py:if="not current_page" py:replace="display_pages(space.root_pages)"/>

</body>

</html>
